package com.kaigejava.rulesengine.engine.core.kie;


import com.kaigejava.rulesengine.engine.dto.RuleHitDto;
import com.kaigejava.rulesengine.engine.fact.RecyclingFact;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 规则引擎执行类
 * @author kaigejava
 */
public class Action {

    private Logger logger = LoggerFactory.getLogger(Action.class);

    private RecyclingFact recyclingFact;

    private Integer ruleId;

    /**
     * 规则名
     */
    private String name;

    private Integer type;

    public Action(Integer ruleId, RecyclingFact recyclingFact) {
        this.ruleId = ruleId;
        this.recyclingFact = recyclingFact;
    }

    /**
     * @param ruleId
     * @param recyclingFact 调用数据
     */
    public Action(Integer ruleId, String name, RecyclingFact recyclingFact) {
        this.ruleId = ruleId;
        this.name = name;
        this.recyclingFact = recyclingFact;
    }

    /**
     * @param ruleId
     * @param recyclingFact 调用数据
     */
    public Action(Integer ruleId, String name, Integer type, RecyclingFact recyclingFact) {
        this.ruleId = ruleId;
        this.name = name;
        this.type = type;
        this.recyclingFact = recyclingFact;
    }

    /**
     * 规则满足执行
     * @param response
     */
    public void doExecute(KieResponse response) {
        response.setCode(0);
        response.setMessage("execute rule ok.");
        RuleHitDto hitDto = new RuleHitDto();
        hitDto.setRuleId(this.ruleId);
        hitDto.setName(this.name);
        hitDto.setType(this.type);
        hitDto.setHit(true);
        response.setResult(hitDto);
        logger.info("命中规则:{}", hitDto);
    }
}
